home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / cgazv4n2.zip / CPP.ZIP / DU.CXX next >
C/C++ Source or Header  |  1989-08-26  |  1KB  |  35 lines

  1. // DU.CXX
  2. #include "filelist.hxx"
  3. // Notice the same framework is used here as with ldir.cxx
  4.  
  5. char * errmsg =
  6. "du in C++ by Bruce Eckel.  Calculates space occupied by directory(s)\n"
  7. "Usage: du [filespec] [flags]\n"
  8. "optional filespec must be second argument, but flags can be\n"
  9. "in any order.  Available options are:\n"
  10. "   -r    calculates subdirectory sizes\n";
  11.  
  12. main(int argc, char ** argv) {
  13.   display_format format = 0;
  14.   char * arg = "*.*";  // file spec defaults to all files
  15.  
  16.   if (argc > 1 && argv[1][0] != '-')
  17.     arg = argv[1];
  18.   // Process the command-line switches
  19.   for(int a = argc -1;  a > 0; a--) {
  20.     if(argv[a][0] == '-') {
  21.       switch ( argv[a][1] ) {
  22.         case 'r' : case 'R' : format |= subdirs; break;
  23.         default :
  24.             fprintf(stderr, "unknown switch: %s\n", argv[a]);
  25.             fprintf(stderr, "%s\n", errmsg);
  26.             exit(1);
  27.       }
  28.     }
  29.   }
  30.   file_list files(arg);
  31.   if(format & subdirs) files.expand_list();
  32.   printf("total used in this subdirectory = %lu\n", files.disk_space());
  33. }
  34.   
  35.